//
//  PhotoCollectionViewCell.m
//  FreeTrip
//
//  Created by 邓芮 on 15/11/26.
//  Copyright © 2015年 邓芮. All rights reserved.
//

#import "PhotoCollectionViewCell.h"

@interface PhotoCollectionViewCell ()

@property (nonatomic, strong) UIImageView *icon;

@end

@implementation PhotoCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        self.icon = [[UIImageView alloc]init];
        self.icon.backgroundColor = [UIColor grayColor];
        [self.contentView addSubview:self.icon];
    
    }
    return self;
}
/*
- (void)layoutSubviews
{
    [super layoutSubviews];
    UIImage *image = self.icon.image;
    CGFloat height = 120 * KScreenWidth / 414;
    CGSize size = image.size;
    CGFloat wigth = height * size.width / size.height;
    self.icon.frame = CGRectMake(0, 0, wigth, height);
   
}
*/

- (void)setModel:(PhotosModel *)model
{
    _model = model;
    self.icon.image = nil;
    [self.icon sd_setImageWithURL:[NSURL URLWithString:model.image_url] placeholderImage:[UIImage imageNamed:@"placeholder"]];
    CGFloat height = 120 * KScreenWidth / 414;
    CGFloat width = model.image_width * height / model.image_height;
//    NSLog(@"w = %ld h = %ld", model.image_width, model.image_height);
//    NSLog(@"%f", width);
    self.icon.frame = CGRectMake(0, 0, width, height);
}

@end
